#pragma once

#include "../../Lib_Base/inc/Types.h"
#include "..\..\Lib_Base\Inc\IMessage.h"
#include "../../Lib_Base/inc/IModule.h"

namespace serve
{	
	enum PORT {PORT_IN,PORT_OUT,PORT_ALL};
	//////////////////////////////////////////////////////////////////////
	class IPort
	{
	public:
		// get port num
		virtual USHORT		GetPort		(void) const	= 0;
		
			
		// validation chk
		virtual bool		IsValid		(void) const	= 0;
		
		// take out a msg from msg port, u should release this msg by ur self
		virtual sbase::IMessage*	TakeMsg	(void)	= 0;

		virtual int                 GetReceiveMsgCount(void)=0;

		virtual int                 GetSendMsgCount(void)=0;
		
		// send a msg to specified msg port
		virtual bool		SendMsg		(sbase::IMessage& msg, int nPortDes) = 0;

		virtual void		CleanMsg	(void)			= 0;
		virtual void		Stop		(void)			= 0;
		virtual void		Start		(void)			= 0;
		virtual void        DiscardMsg  (sbase::IMessage* pMsg)=0;
		virtual size_t         GetCountOut    ()              = 0;
		virtual size_t         GetCountIn    ()               = 0;
	};
	
	//////////////////////////////////////////////////////////////////////
	class IServe : public sbase::IModule
	{
	public:
		virtual USHORT		GetInterval	(void) const					= 0;
		virtual USHORT		GetPort		(void) const					= 0;
		virtual void		SendMsg		(sbase::IMessage& msg, int nPortDes)= 0;
		virtual int			OnProcess	(void)							= 0;
		virtual void        CloseSock   (int socket)                 = 0;
		virtual int TotalSocket(char type)=0;
	};

	class IRouter
	{
	public:
		virtual serve::IPort*		QueryPort(ULONG usPort)	const	= 0;
	};
}

typedef serve::IServe*(*funServeCreate)(serve::IRouter* pRouter, USHORT usInterval);


